package com.gitee.zycra.union.api.service;

import com.gitee.zycra.union.api.common.bo.CommonResult;
import com.gitee.zycra.union.api.common.param.AddProjectParam;
import com.gitee.zycra.union.api.common.param.UpdateProjectParam;
import com.gitee.zycra.union.api.common.vo.ProjectDetailVO;
import com.gitee.zycra.union.api.common.vo.ProjectVO;
import com.gitee.zycra.union.api.manager.ApiProjectManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zycra
 */
@Slf4j
@Service
public class ApiProjectService {

    @Autowired
    private ApiProjectManager apiProjectManager;

    /**
     * 添加项目
     *
     * @param addProjectParam 项目
     * @return 添加结果
     */
    public CommonResult<String> addProject(AddProjectParam addProjectParam) {
        apiProjectManager.addProject(addProjectParam);
        return CommonResult.success();
    }

    /**
     * 根据ID更新项目
     *
     * @param updateProjectParam 项目
     * @return 更新结果
     */
    public CommonResult<String> updateProject(UpdateProjectParam updateProjectParam) {
        apiProjectManager.updateProject(updateProjectParam);
        return CommonResult.success();
    }

    /**
     * 根据ID删除项目
     *
     * @param groupId 项目组ID
     * @param id      项目ID
     * @return 更新结果
     */
    public CommonResult<String> deleteProject(Long groupId, Long id) {
        apiProjectManager.deleteProject(groupId, id);
        return CommonResult.success();
    }

    /**
     * 根据项目组ID查询项目
     *
     * @param groupId 项目组ID
     * @return 项目集合
     */
    public CommonResult<List<ProjectVO>> projectList(Long groupId) {
        return CommonResult.success(apiProjectManager.projectList(groupId));
    }

    /**
     * 根据项目ID查询项目
     *
     * @param groupId   项目组ID
     * @param projectId 项目ID
     * @return 项目
     */
    public CommonResult<ProjectDetailVO> projectDetail(Long groupId, Long projectId) {
        return CommonResult.success(apiProjectManager.projectDetail(groupId, projectId));
    }
}
